home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.basic.AbstractTreeUI;
- import com.sun.java.swing.plaf.basic.BasicTreeUI;
- import com.sun.java.swing.plaf.basic.LargeTreeModelNode;
- import com.sun.java.swing.plaf.basic.VisibleTreeNode;
- import com.sun.java.swing.tree.DefaultMutableTreeNode;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.beans.PropertyChangeListener;
-
- public class MetalTreeUI extends BasicTreeUI {
- private static Color lineColor;
- private static final String LINE_STYLE = "JTree.lineStyle";
- private static final String LEG_LINE_STYLE_STRING = "Angled";
- private static final String HORIZ_STYLE_STRING = "Horizontal";
- private static final String NO_STYLE_STRING = "None";
- private static final int LEG_LINE_STYLE = 2;
- private static final int HORIZ_LINE_STYLE = 1;
- private static final int NO_LINE_STYLE = 0;
- private int lineStyle = 1;
- private PropertyChangeListener lineStyleListener = new LineListener(this);
-
- protected boolean clickedInExpandControl(VisibleTreeNode node, LargeTreeModelNode eNode, int row, int rowLevel, int mouseX, int mouseY) {
- if (node != null && node.isLeaf()) {
- return false;
- } else {
- int boxWidth;
- if (((BasicTreeUI)this).getExpandedIcon() != null) {
- boxWidth = ((BasicTreeUI)this).getExpandedIcon().getIconWidth() + 6;
- } else {
- boxWidth = 8;
- }
-
- int boxLeftX;
- if (((AbstractTreeUI)this).getShowsRootHandles()) {
- boxLeftX = rowLevel * super.totalChildIndent + ((BasicTreeUI)this).getLeftChildIndent() - boxWidth / 2;
- } else {
- boxLeftX = (rowLevel - 1) * super.totalChildIndent + ((BasicTreeUI)this).getLeftChildIndent() - boxWidth / 2;
- }
-
- int boxRightX = boxLeftX + boxWidth;
- return mouseX >= boxLeftX && mouseX <= boxRightX;
- }
- }
-
- public static ComponentUI createUI(JComponent x) {
- return new MetalTreeUI();
- }
-
- protected void decodeLineStyle(Object lineStyleFlag) {
- if (lineStyleFlag != null && !lineStyleFlag.equals("Horizontal")) {
- if (lineStyleFlag.equals("Angled")) {
- this.lineStyle = 2;
- } else if (lineStyleFlag.equals("None")) {
- this.lineStyle = 0;
- }
- } else {
- this.lineStyle = 1;
- }
-
- }
-
- public void drawHorizontalPartOfLeg(Graphics g, JComponent c, int lineY, int leftX, int rightX) {
- if (this.lineStyle == 2) {
- super.drawHorizontalPartOfLeg(g, c, lineY, leftX, rightX);
- }
-
- }
-
- public void drawVerticalPartOfLeg(Graphics g, JComponent c, int depth, int parentY, int childY, int parentRowHeight, int childRowHeight) {
- if (this.lineStyle == 2) {
- super.drawVerticalPartOfLeg(g, c, depth, parentY, childY, parentRowHeight, childRowHeight);
- }
-
- }
-
- protected int getHorizontalLegBuffer() {
- return 4;
- }
-
- public void installUI(JComponent c) {
- super.installUI(c);
- if (!super.tree.isLargeModel()) {
- ((AbstractTreeUI)this).setRowHeight(0);
- }
-
- lineColor = UIManager.getColor("Tree.line");
- Object lineStyleFlag = c.getClientProperty("JTree.lineStyle");
- this.decodeLineStyle(lineStyleFlag);
- c.addPropertyChangeListener(this.lineStyleListener);
- }
-
- public void paint(Graphics g, JComponent c) {
- super.paint(g, c);
- if (this.lineStyle == 1 && !super.largeModel) {
- this.paintHorizontalSeparators(g, c);
- }
-
- }
-
- protected void paintHorizontalSeparators(Graphics g, JComponent c) {
- g.setColor(lineColor);
- Rectangle clipBounds = g.getClipBounds();
- int beginRow = ((AbstractTreeUI)this).getRowContainingYLocation(clipBounds.y);
- int endRow = ((AbstractTreeUI)this).getRowContainingYLocation(clipBounds.y + (clipBounds.height - 1));
- if (beginRow > -1 && endRow > -1) {
- for(int i = beginRow; i <= endRow; ++i) {
- VisibleTreeNode node = ((AbstractTreeUI)this).getNode(i);
- if (((DefaultMutableTreeNode)node).getParent() == ((DefaultMutableTreeNode)node).getRoot()) {
- g.drawLine(clipBounds.x, ((BasicTreeUI)this).getNodeY(node), clipBounds.x + clipBounds.width, ((BasicTreeUI)this).getNodeY(node));
- }
- }
-
- }
- }
-
- public void uninstallUI(JComponent c) {
- c.removePropertyChangeListener(this.lineStyleListener);
- super.uninstallUI(c);
- }
- }
-